package com.omt.tarjimdinek.domain.translate.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotEmpty;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Sahabi;
import com.omt.tarjimdinek.domain.tv.entity.Intervenant;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * original line of translation
 * @author chabane
 *
 */
@Entity
@Table(name="a01_lgnorg")
public class LigneOriginale implements Identifiable<Long>, Serializable{

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(LigneOriginale.class);
    
	/** ID SGBD */
	@Column(name="CNLGNORG", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	@Column(name = "VERSION", precision = 10)
	@Version
	private Integer version;
	
	/** begin time */
	@NotNull
	@Column(name="INTMPDB", length=2, nullable=false)
	private Integer tempsDebut;
	
	/** end time */
	@NotNull
	@Column(name="INTMPFN", length=2, nullable=false)
	private Integer tempsFin;
	
	/** speaker of line */
	@JoinColumn(name = "CNINTV", nullable = false)
	@ManyToOne
	private Intervenant intervenant;
	
	/** content of line */
	@JoinColumn(name="CNLGN", nullable=false)
	@NotNull
	private Ligne contenuAtraduire;
	
	/** color code */
	@Size(max = 6)
	@NotEmpty
	@Column(name="LICDCLR", length=6, nullable=false)
	private String codeCouleur;
	
	/** translation request */
	@JoinColumn(name="CNDMDTRD")
	@ManyToOne
	private DemandeTraduction demandeTraduction;
	
	@JoinColumn(name="CNLGNTRD", nullable=false)
	@OneToOne(mappedBy="ligneOriginale", cascade=CascadeType.ALL)
	private LigneTraduction ligneTraduction;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	
	public Integer getTempsDebut() {
		return tempsDebut;
	}

	public void setTempsDebut(Integer tempsDebut) {
		this.tempsDebut = tempsDebut;
	}

	public Integer getTempsFin() {
		return tempsFin;
	}

	public void setTempsFin(Integer tempsFin) {
		this.tempsFin = tempsFin;
	}

	public Intervenant getIntervenant() {
		return intervenant;
	}

	public void setIntervenant(Intervenant intervenant) {
		this.intervenant = intervenant;
	}

	public Ligne getContenuAtraduire() {
		return contenuAtraduire;
	}

	public void setContenuAtraduire(Ligne contenuAtraduire) {
		this.contenuAtraduire = contenuAtraduire;
	}

	public String getCodeCouleur() {
		return codeCouleur;
	}

	public void setCodeCouleur(String codeCouleur) {
		this.codeCouleur = codeCouleur;
	}

	public DemandeTraduction getDemandeTraduction() {
		return demandeTraduction;
	}

	public void setDemandeTraduction(DemandeTraduction demandeTraduction) {
		this.demandeTraduction = demandeTraduction;
	}
	
	public LigneTraduction getLigneTraduction() {
		return ligneTraduction;
	}

	public void setLigneTraduction(LigneTraduction ligneTraduction) {
		this.ligneTraduction = ligneTraduction;
	}

	@Transient
	public boolean isIdSet() {
		return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}
	
	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }

    public int hashCode() {
        int hashCode = Objects.hashCode(getId());
        return hashCode;
    }
    
    /**
     * Construct a readable string representation for this instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("codeCouleur", getCodeCouleur()) //
                .add("demandeTraduction", getDemandeTraduction()) //
                .add("intervenant", getIntervenant()) //
                .add("ligneTraduction", getLigneTraduction()) //
                .add("listeLignes", getContenuAtraduire()) //
                .add("tempsDebut", getTempsDebut()) //
                .add("tempsFin", getTempsFin()) //
                .add("version", getVersion()) //
                .toString();
    }
}
